// pages/jiameng/jiameng.js
const app=getApp();
//获得全局js变量
var util = require('../../utils/util.js');
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
        imgurl:app.data.imgurl,
        name: '',//姓名
        phone: '',//电话
        cardnum:'',//详细地址
        banktype:'',//银行卡类型
        opbank:'',//开户行
        btnable: true,
        id:0
	},
    //输入框监听
    bindinput: function (e) {
        //console.log(e);
        var value = e.detail.value;
        var type = e.currentTarget.dataset.type;
        if (type.length > 0) {
            switch (type) {
                case 'name': //姓名
                    this.setData({
                        name: value,
                    })
                    break;
                case 'phone': //手机号码
                    this.setData({
                        phone: value,
                    })
                    break;
                case 'cardnum': //银行卡号
                    this.setData({
                        cardnum: value,
                    })
                    break;
                case 'banktype': //银行卡类型
                    this.setData({
                        banktype: value,
                    })
                    break;
                case 'opbank': //开户行
                    this.setData({
                        opbank: value,
                    })
                    break;
            }
        }
        //console.log(this.data);
    },
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
        
        //判断是否有正在申请的加盟信息
        this.getsqjoin();
	},
    getsqjoin:function(){
        var that = this
        var userId = app.globalData.userId;
        util.httpRrquest(app.data.rooturl + 'user/getBankcard', 'GET', {userid:userId})
            .then(function (response) {  
                var data = response.data.data;
                console.log(data);
                if(data['hasData'] == 1){
                    that.setData({//已存在申请
                        name: data.name,//姓名
                        phone: data.phone,//电话
                        cardnum: data.cardnum,//银行卡号
                        banktype: data.banktype,//银行卡类型
                        opbank: data.opbank//开户行
                        
                    });
                }
            }, function (error) {
                console.log(error);
            });
    },
    joinsq: function () {
        var that = this
        if (that.data.name.length <= 0 || that.data.phone.length <= 0 || that.data.cardnum.length <= 0 || that.data.banktype.length <= 0 || that.data.opbank.length <= 0 ) {
            wx.showToast({
                title: '请正确输入信息...',
                icon: 'none',
                duration: 2000
            })
            return;
        }
        this.setData({
            btnable: false,
        })
        var userId = app.globalData.userId;
        var postdata = {
            userid: userId,
            name: that.data.name,
            phone: that.data.phone,
            cardnum: that.data.cardnum,
            banktype: that.data.banktype,
            opbank: that.data.opbank
        }
        util.httpRrquest(app.data.rooturl + 'user/joinBankcard', 'POST', postdata)
        .then(function (response) {
            wx.showToast({
                title: response.data.msg,
                icon: 'none',
                duration: 2000
            })
            setTimeout(function () {
                wx.navigateBack({
                    delta: 1
                })
            }, 2000);
        }, function (error) {
            console.log(error);
        });
    },
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {
        var shareinfo = app.setShareMessage();
        console.log(shareinfo);
        return {
            title: shareinfo.title,
            path: shareinfo.path,
            imageUrl: shareinfo.imageUrl,
            success: (res) => {
                wx.showToast({
                    title: "分享成功",
                    icon: 'loading'
                })
            }
        }
	},
    bindRegionChange: function (e) {
        console.log('picker发送选择改变，携带值为', e.detail.value)
        console.log('picker发送选择改变，携带值为', e.detail.code)
        console.log('picker发送选择改变，携带值为', e.detail.postcode)
        var value = e.detail.value;
        this.setData({
            region: e.detail.value,
            sheng: value[0],
            shi: value[1],
            qu: value[2],
        })
    }
})